var dataSource = new Array();
//table的数据源
var table;   //table对象
dataSource = [];


initTable66()
function initTable66() {
    $.ajax({

        url:root.member.listIntegralManage,
        cache: false,  //禁用缓存
        contentType: 'application/x-www-form-urlencoded',
        type: "post",
        data: {
            pageNum: 1,
            pageSize: 5,
            loginAccount:$("#loginAccount").val(),
            mobile: $("#mobile").val(),
        },
        success: function (data) {
            initTabls(data.data.result, 0);
            $('.M-box3').pagination({
                pageCount: data.data.totalPage,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    $.ajax({
                        url: root.member.listIntegralManage,
                        cache: false, //禁用缓存
                        contentType: 'application/x-www-form-urlencoded',
                        type: "post",
                        data: {
                            pageNum: api.getCurrent(),
                            pageSize: 5,
                            loginAccount:$("#loginAccount").val(),
                            mobile: $("#mobile").val(),
                        },
                        success: function (result) {
                            initTabls(result.data.result);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });
                }
            });

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
function initTabls(data) {

    sessionStorage.setItem("authorizedUsers", JSON.stringify(data));
    dataSource.splice(0,dataSource.length);//清空数组

    $.each(data, function (i, field) {
        var rowData = new Array();
        rowData.push(field.loginAccount);
        rowData.push(field.mobile);
        rowData.push(field.levelName);
        rowData.push(field.memberId);
        dataSource.push(rowData);

    });

    initDataTable(dataSource);

    function initDataTable(dataSource) {

        var dttable = $('#excludetable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#excludetable").DataTable({
            // "order": false,
            "autoWidth": false,
            "ordering": false,
            "searching": false,
            "paging": false,
            "retrieve": true,
            "destroy": true,
            "bAutoWidth": true,
            "bLengthChange": true,
            "aLengthMenu": false,
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
            },
            data: dataSource,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function(data, type, row, meta) {
                        var val = '<span style="text-align: left;"><td><input name="radio" value=' + row[0]+','+row[1]+','+row[3]+'  class="bei"  type="radio" tag="0" /></span>';
                        return val;
                    },
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[0]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 1
                },


                {
                    "render": function (data, type, row, meta) {
                        var val = row[1]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 2
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[2]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 3
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = '<input  type="text" class="input-text radius beizhu"  placeholder="请填写备注信息" maxlength="200" name="ee"    style="height: 29px;width: 378px;" id="beizhu" autocomplete="off" >'
                        return val;
                    },
                    "targets": 4
                },


            ]
        });
    };
}
var beizhus=""//备注信息
//保存
function add() {

    //获取备注信息
    var radio=document.getElementsByName("radio");

    var selectvalue=null;   //  selectvalue为radio中选中的值
    for(var  i=0;i<radio.length;i++){

        if(radio[i].checked==true) {

            selectvalue=radio[i];

            break;

        }

    }
    var lleve=$(selectvalue).parent().parent().parent().find(".beizhu")

    beizhus=$(lleve).val()
    //判断是否选中状态
    var val=$('input:radio[name="radio"]:checked').val();

    if(val!=null){ //是否被选中
        if(beizhus==""){
            $.Huimodalalert('请填写备注信息',2000);
            return false
        }

    }else {

        $.Huimodalalert('请选择会员，再提交',2000);

    }
    var loginAccounts=val.split(",")[0]
    var mobiles= val.split(",")[1]
    var memberId= val.split(",")[2]

    $.ajax({
        url:root.member.insertIntegralExclude,
        cache: false,  //禁用缓存
        contentType: 'application/x-www-form-urlencoded',
        type: "post",
        data: {
            loginAccount:loginAccounts,
            mobile: mobiles,
            remarks: beizhus,
            memberId:memberId
        },
        success: function (data) {
     if(data.errorCode==0){
         layer.msg("添加成功",{icon: 6,time:2000},function () {
             /*var index = parent.layer.getFrameIndex(window.name);
             parent.layer.close(index);*/ //跳转父页面
             setTimeout(function () {
                 parent.initTable22();
                 removeThisIframe();
             })
         });
     }else {
         $.Huimodalalert(data.msg,2000);
     }
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });






}
/*关闭详情页*/
function removeThisIframe() {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}